﻿using System;
using UnityEngine;

// Token: 0x0200006B RID: 107
public class GuideDrive_Pos : GuideDrive
{
	// Token: 0x0600037D RID: 893 RVA: 0x00016110 File Offset: 0x00014310
	private void Start()
	{
		base.Init();
	}

	// Token: 0x0600037E RID: 894 RVA: 0x00016118 File Offset: 0x00014318
	private void Update()
	{
		if (this.onMove)
		{
			if (this.moveType == GuideDrive_Pos.MoveType.XY || this.moveType == GuideDrive_Pos.MoveType.YZ || this.moveType == GuideDrive_Pos.MoveType.XZ)
			{
				Vector3 move = this.PlanePos(Input.mousePosition) - this.PlanePos(this.movePrevPos);
				this.movePrevPos = Input.mousePosition;
				this.manager.DriveMovePosition(move);
			}
			else
			{
				Vector3 vector = this.AxisPos(Input.mousePosition) - this.AxisPos(this.movePrevPos);
				this.movePrevPos = Input.mousePosition;
				Vector3 ab = Vector3.zero;
				ab = base.transform.rotation * new Vector3(0f, 1f, 0f);
				vector = this.ClosestPoint(vector, Vector3.zero, ab);
				this.manager.DriveMovePosition(vector);
			}
			if (Input.GetMouseButtonUp(0))
			{
				this.OnMoveEnd();
				this.manager.OnMoveEnd(this);
			}
		}
	}

	// Token: 0x0600037F RID: 895 RVA: 0x00016218 File Offset: 0x00014418
	private Vector3 PlanePos(Vector3 screenPos)
	{
		Vector3 inNormal = base.transform.rotation * Vector3.up;
		Plane plane = new Plane(inNormal, base.transform.position);
		Ray ray = Camera.main.ScreenPointToRay(screenPos);
		float distance = 0f;
		if (plane.Raycast(ray, out distance))
		{
			return ray.GetPoint(distance);
		}
		return this.manager.transform.position;
	}

	// Token: 0x06000380 RID: 896 RVA: 0x00016288 File Offset: 0x00014488
	private Vector3 AxisPos(Vector3 screenPos)
	{
		Vector3 rhs = Camera.main.transform.rotation * Vector3.forward;
		Vector3 vector = Vector3.zero;
		vector = base.transform.rotation * new Vector3(0f, 1f, 0f);
		Vector3 b = Vector3.Cross(vector, rhs);
		Vector3 position = base.transform.position;
		Vector3 b2 = base.transform.position + vector;
		Vector3 c = base.transform.position + b;
		Plane plane = new Plane(position, b2, c);
		Ray ray = Camera.main.ScreenPointToRay(screenPos);
		float distance = 0f;
		if (plane.Raycast(ray, out distance))
		{
			return ray.GetPoint(distance);
		}
		return this.manager.transform.position;
	}

	// Token: 0x06000381 RID: 897 RVA: 0x00016360 File Offset: 0x00014560
	private Vector3 ClosestPoint(Vector3 point, Vector3 center, Vector3 ab)
	{
		float d = Vector3.Dot(point - center, ab) / Vector3.Dot(ab, ab);
		return center + ab * d;
	}

	// Token: 0x0400030D RID: 781
	public GuideDrive_Pos.MoveType moveType;

	// Token: 0x0400030E RID: 782
	public float speed = 0.001f;

	// Token: 0x0200006C RID: 108
	public enum MoveType
	{
		// Token: 0x04000310 RID: 784
		X = 1,
		// Token: 0x04000311 RID: 785
		Y,
		// Token: 0x04000312 RID: 786
		Z = 4,
		// Token: 0x04000313 RID: 787
		XY = 3,
		// Token: 0x04000314 RID: 788
		YZ = 6,
		// Token: 0x04000315 RID: 789
		XZ = 5,
		// Token: 0x04000316 RID: 790
		XYZ = 7
	}
}
